import Vue from 'vue'
import VueRouter from 'vue-router'
import login from '../views/login/index.vue'
import homepage from '../views/home-page/HomePage.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    component: login
  },
  {
    path: '/homepage',
    component: homepage
  }
]



const router = new VueRouter({
  routes
})


// router.beforeEach((to, from, next) => {
//   // to将要访问的路径
//   // from从哪个路径来
//   // next()直接放行, next('/xxx')强制跳转
//   if (to.path === '/login') return next()
//   const tokenStr = window.sessionStorage.getItem('token')
//   if (!tokenStr) return next('/login')
//   next()
// })

export default router
